﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;

namespace ChinaDynastyTours.Controls
{
    class CashDetailCtrl
    {
        #region 报销详情信息查询

        /// <summary>
        /// 根据付款申请单ID获取付款详情信息
        /// </summary>
        /// <param name="expenseId"></param>
        /// <returns></returns>
        internal static DataTable GetCashDetailDataByCashApplyId(string cashApplyId)
        {

            Database db = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand;

            string Sql = string.Format(@"SELECT *  FROM  vw_CashDetail WHERE ItemID={0}", cashApplyId);

            dbCommand = db.GetSqlStringCommand(Sql);

            DataSet ds = db.ExecuteDataSet(dbCommand);
            if (ds.Tables.Count > 0)
                return ds.Tables[0];
            else
                return null;
        }

        /// <summary>
        /// 根据费用ID获取付款详情信息
        /// </summary>
        /// <param name="expenseId"></param>
        /// <returns></returns>
        internal static DataTable GetCashDetailDataByExpenseID(string expenseId)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand;
            string Sql = string.Format(@"SELECT *  FROM  vw_CashDetail WHERE ExpenseID={0} AND Status<>'{1}'", expenseId, ExpenseStatusEnum.取消);

            dbCommand = db.GetSqlStringCommand(Sql);

            DataSet ds = db.ExecuteDataSet(dbCommand);
            if (ds.Tables.Count > 0)
                return ds.Tables[0];
            else
                return null;
        }
        #endregion

        /// <summary>
        /// 补充摘要
        /// </summary>
        /// <param name="remark"></param>
        /// <param name="payDetailId"></param>
        /// <returns></returns>
        internal static int UpdateCashDetailRemark(string remark, string cashDetailId)
        {
            Database db = DatabaseFactory.CreateDatabase();
            string sql = string.Format(@"UPDATE fin_CashDetail SET [Remark]='{0}' WHERE CashDetailID={1}", remark, cashDetailId);

            return db.ExecuteNonQuery(CommandType.Text, sql);
        }
    }
}
